package com.ms.cmdlinetool;

import org.hibernate.HibernateException;

import com.xpec.c4.db.hibernate.manager.ConfigurationManager;
import com.xpec.c4.db.hibernate.manager.HibernateAnalysisManager;
import com.xpec.c4.db.hibernate.manager.HibernateBusinessManager;
import com.xpec.c4.db.hibernate.manager.HibernateLogManager;
import com.xpec.c4.db.hibernate.manager.HibernateManager;
import com.xpec.c4.game.utility.GUIDFactory;


/*
 * Miriam Chen
 * 用來初始建立系統需用的database tables
 */
public class BuildDatabaseTables {
	
	public static void build(){
		ConfigurationManager.setAutoCreateTables(true);
		try {
			HibernateManager.getSession();
			HibernateLogManager.getSession();
			HibernateBusinessManager.getSession();
			HibernateAnalysisManager.getSession();

			//********************
			HibernateManager.destroySessionFactory();
			HibernateLogManager.destroySessionFactory();
			HibernateBusinessManager.destroySessionFactory();
			HibernateAnalysisManager.destroySessionFactory();
			ConfigurationManager.resetConfigs();
		} catch (HibernateException e) {
			e.printStackTrace();
		} finally {
			ConfigurationManager.setAutoCreateTables(false);
		}
	}

	public static void main(String[] args) {
		GUIDFactory.setProcessId(1);
		build();
		
		
		if(args != null && args.length > 0){
			
			// 查看cmd內容
			String cmd = args[0];
			
			// 只要包含r就表示要建循環表
			if(cmd.contains("r")){
				BuildDatabaseRecycleLogTables.main(null);
			}
			
		}
		
	}
	

}
